#include "myudp.h"
#include <QDebug>

MyUdp::MyUdp(QObject *parent)
    : QObject(parent)
{
    socket = new QUdpSocket(this);
    socket->bind(QHostAddress::LocalHost, 1234);
    connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
}

void MyUdp::HelloUpd()
{
    QByteArray Data;
    Data.append("Hello From Udp");
    socket->writeDatagram(Data, QHostAddress::LocalHost, 1234);
}

MyUdp::~MyUdp()
{

}

void MyUdp::readyRead()
{
    QByteArray buffer;
    buffer.resize(socket->pendingDatagramSize());

    QHostAddress sender;
    quint16 senderPort;
    socket->readDatagram(buffer.data(), buffer.size(), &sender, &senderPort);

    qDebug() << "Message From: " << sender.toString();
    qDebug() << "Message Port: " << senderPort;
    qDebug() << "Message: " << buffer;
}
